const Koa=require('koa');
const path=require('path')
const static=require('koa-static');
const body=require('koa-better-body')
const router=require('./router')
const compress=require('koa-compress')
let server=new Koa();
server.use(compress({threshold:1024}))
server.context.db=require('./libs/query');
server.context.unlink=require('./libs/unlink')
server.use(static('./static'))
server.use(body({
  uploadDir:path.resolve(__dirname,'./static/upload')
}))
server.use(async (ctx,next)=>{
  ctx.set('Access-Control-Allow-Origin', '*')
  ctx.set("Access-Control-Allow-Headers", "*");
  if (ctx.method === 'OPTIONS') {
    ctx.body = '';
  }
  // ctx.set("Access-Control-Allow-Headers", "authorization")
  await next()
})
server.use(router.routes())
server.listen(3005)